using System;
using System.Data;
using System.Data.SqlTypes;
using System.Data.SqlClient;

namespace DataEntity
{
    public class T_Project_ProjectCommission : DBInteractionBase
	{
		#region Class Member Declarations
			private SqlDateTime		_project_ProjectCommission_Date;
			private SqlInt32		_project_ProjectCommission_Status, _project_ProjectCommission_AgentID;
			private SqlGuid			_project_ProjectCommission_ID, _project_ProjectCommission_ProjectID;
		#endregion


		public T_Project_ProjectCommission()
		{
			// Nothing for now.
		}





		public override bool Update()
		{
			SqlCommand	cmdToExecute = new SqlCommand();
			cmdToExecute.CommandText = "dbo.[sp_t_Project_ProjectCommission_Update]";
			cmdToExecute.CommandType = CommandType.StoredProcedure;

			// Use base class' connection object
			cmdToExecute.Connection = _mainConnection;

			try
			{
				cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_ProjectCommission_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_ProjectCommission_ID));
				cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_ProjectCommission_ProjectID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_ProjectCommission_ProjectID));
				cmdToExecute.Parameters.Add(new SqlParameter("@iProject_ProjectCommission_AgentID", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _project_ProjectCommission_AgentID));
				cmdToExecute.Parameters.Add(new SqlParameter("@daProject_ProjectCommission_Date", SqlDbType.DateTime, 8, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_ProjectCommission_Date));
				cmdToExecute.Parameters.Add(new SqlParameter("@iProject_ProjectCommission_Status", SqlDbType.Int, 4, ParameterDirection.Input, false, 10, 0, "", DataRowVersion.Proposed, _project_ProjectCommission_Status));

				if(_mainConnectionIsCreatedLocal)
				{
					// Open connection.
					_mainConnection.Open();
				}
				else
				{
					if(_mainConnectionProvider.IsTransactionPending)
					{
						cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
					}
				}

				// Execute query.
				_rowsAffected = cmdToExecute.ExecuteNonQuery();
				return true;
			}
			catch(Exception ex)
			{
				// some error occured. Bubble it to caller and encapsulate Exception object
				throw new Exception("T_Project_ProjectCommission::Update::Error occured.", ex);
			}
			finally
			{
				if(_mainConnectionIsCreatedLocal)
				{
					// Close connection.
					_mainConnection.Close();
				}
				cmdToExecute.Dispose();
			}
		}


		public override bool Delete()
		{
			SqlCommand	cmdToExecute = new SqlCommand();
			cmdToExecute.CommandText = "dbo.[sp_t_Project_ProjectCommission_Delete]";
			cmdToExecute.CommandType = CommandType.StoredProcedure;

			// Use base class' connection object
			cmdToExecute.Connection = _mainConnection;

			try
			{
				cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_ProjectCommission_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_ProjectCommission_ID));

				if(_mainConnectionIsCreatedLocal)
				{
					// Open connection.
					_mainConnection.Open();
				}
				else
				{
					if(_mainConnectionProvider.IsTransactionPending)
					{
						cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
					}
				}

				// Execute query.
				_rowsAffected = cmdToExecute.ExecuteNonQuery();
				return true;
			}
			catch(Exception ex)
			{
				// some error occured. Bubble it to caller and encapsulate Exception object
				throw new Exception("T_Project_ProjectCommission::Delete::Error occured.", ex);
			}
			finally
			{
				if(_mainConnectionIsCreatedLocal)
				{
					// Close connection.
					_mainConnection.Close();
				}
				cmdToExecute.Dispose();
			}
		}


		public override DataTable SelectOne()
		{
			SqlCommand	cmdToExecute = new SqlCommand();
			cmdToExecute.CommandText = "dbo.[sp_t_Project_ProjectCommission_SelectOne]";
			cmdToExecute.CommandType = CommandType.StoredProcedure;
			DataTable toReturn = new DataTable("t_Project_ProjectCommission");
			SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);

			// Use base class' connection object
			cmdToExecute.Connection = _mainConnection;

			try
			{
				cmdToExecute.Parameters.Add(new SqlParameter("@guidProject_ProjectCommission_ID", SqlDbType.UniqueIdentifier, 16, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, _project_ProjectCommission_ID));

				if(_mainConnectionIsCreatedLocal)
				{
					// Open connection.
					_mainConnection.Open();
				}
				else
				{
					if(_mainConnectionProvider.IsTransactionPending)
					{
						cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
					}
				}

				// Execute query.
				adapter.Fill(toReturn);
				if(toReturn.Rows.Count > 0)
				{
					_project_ProjectCommission_ID = (Guid)toReturn.Rows[0]["Project_ProjectCommission_ID"];
					_project_ProjectCommission_ProjectID = (Guid)toReturn.Rows[0]["Project_ProjectCommission_ProjectID"];
					_project_ProjectCommission_AgentID = (Int32)toReturn.Rows[0]["Project_ProjectCommission_AgentID"];
					_project_ProjectCommission_Date = toReturn.Rows[0]["Project_ProjectCommission_Date"] == System.DBNull.Value ? SqlDateTime.Null : (DateTime)toReturn.Rows[0]["Project_ProjectCommission_Date"];
					_project_ProjectCommission_Status = toReturn.Rows[0]["Project_ProjectCommission_Status"] == System.DBNull.Value ? SqlInt32.Null : (Int32)toReturn.Rows[0]["Project_ProjectCommission_Status"];
				}
				return toReturn;
			}
			catch(Exception ex)
			{
				// some error occured. Bubble it to caller and encapsulate Exception object
				throw new Exception("T_Project_ProjectCommission::SelectOne::Error occured.", ex);
			}
			finally
			{
				if(_mainConnectionIsCreatedLocal)
				{
					// Close connection.
					_mainConnection.Close();
				}
				cmdToExecute.Dispose();
				adapter.Dispose();
			}
		}


		public override DataTable SelectAll()
		{
			SqlCommand	cmdToExecute = new SqlCommand();
			cmdToExecute.CommandText = "dbo.[sp_t_Project_ProjectCommission_SelectAll]";
			cmdToExecute.CommandType = CommandType.StoredProcedure;
			DataTable toReturn = new DataTable("t_Project_ProjectCommission");
			SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);

			// Use base class' connection object
			cmdToExecute.Connection = _mainConnection;

			try
			{

				if(_mainConnectionIsCreatedLocal)
				{
					// Open connection.
					_mainConnection.Open();
				}
				else
				{
					if(_mainConnectionProvider.IsTransactionPending)
					{
						cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
					}
				}

				// Execute query.
				adapter.Fill(toReturn);
				return toReturn;
			}
			catch(Exception ex)
			{
				// some error occured. Bubble it to caller and encapsulate Exception object
				throw new Exception("T_Project_ProjectCommission::SelectAll::Error occured.", ex);
			}
			finally
			{
				if(_mainConnectionIsCreatedLocal)
				{
					// Close connection.
					_mainConnection.Close();
				}
				cmdToExecute.Dispose();
				adapter.Dispose();
			}
		}


		#region Class Property Declarations
		public SqlGuid Project_ProjectCommission_ID
		{
			get
			{
				return _project_ProjectCommission_ID;
			}
			set
			{
				SqlGuid project_ProjectCommission_IDTmp = (SqlGuid)value;
				if(project_ProjectCommission_IDTmp.IsNull)
				{
					throw new ArgumentOutOfRangeException("Project_ProjectCommission_ID", "Project_ProjectCommission_ID can't be NULL");
				}
				_project_ProjectCommission_ID = value;
			}
		}


		public SqlGuid Project_ProjectCommission_ProjectID
		{
			get
			{
				return _project_ProjectCommission_ProjectID;
			}
			set
			{
				SqlGuid project_ProjectCommission_ProjectIDTmp = (SqlGuid)value;
				if(project_ProjectCommission_ProjectIDTmp.IsNull)
				{
					throw new ArgumentOutOfRangeException("Project_ProjectCommission_ProjectID", "Project_ProjectCommission_ProjectID can't be NULL");
				}
				_project_ProjectCommission_ProjectID = value;
			}
		}


		public SqlInt32 Project_ProjectCommission_AgentID
		{
			get
			{
				return _project_ProjectCommission_AgentID;
			}
			set
			{
				SqlInt32 project_ProjectCommission_AgentIDTmp = (SqlInt32)value;
				if(project_ProjectCommission_AgentIDTmp.IsNull)
				{
					throw new ArgumentOutOfRangeException("Project_ProjectCommission_AgentID", "Project_ProjectCommission_AgentID can't be NULL");
				}
				_project_ProjectCommission_AgentID = value;
			}
		}


		public SqlDateTime Project_ProjectCommission_Date
		{
			get
			{
				return _project_ProjectCommission_Date;
			}
			set
			{
				SqlDateTime project_ProjectCommission_DateTmp = (SqlDateTime)value;
				if(project_ProjectCommission_DateTmp.IsNull)
				{
					throw new ArgumentOutOfRangeException("Project_ProjectCommission_Date", "Project_ProjectCommission_Date can't be NULL");
				}
				_project_ProjectCommission_Date = value;
			}
		}


		public SqlInt32 Project_ProjectCommission_Status
		{
			get
			{
				return _project_ProjectCommission_Status;
			}
			set
			{
				SqlInt32 project_ProjectCommission_StatusTmp = (SqlInt32)value;
				if(project_ProjectCommission_StatusTmp.IsNull)
				{
					throw new ArgumentOutOfRangeException("Project_ProjectCommission_Status", "Project_ProjectCommission_Status can't be NULL");
				}
				_project_ProjectCommission_Status = value;
			}
		}
		#endregion
	}
}
